<script setup>
import { ref, onMounted, onBeforeUnmount } from "vue"
import { useRouter } from "vue-router"
const router = useRouter()

let time = ref(3)

onMounted(() => {
  //倒计时
  var timer = setInterval(() => {
    time.value--
    if (time.value < 1) {
      //清除倒计时
      clearInterval(timer)
    }
    if (time.value == 0) {
      handleClick()
    }
  }, 1000)
})

function handleClick() {
  router.push({
    path: "Detail",
  })
}
// onBeforeUnmount(()=>{

// })
</script>
<template>
  <div id="container">
    <div id="skip" @click="handleClick">跳过广告{{ time }}s</div>
  </div>
</template>
<style>
* {
  margin: 0;
  padding: 0;
}
#container {
  width: 100vw;
  height: 100vh;
  background: url("../assets/images/Advert.jpeg") no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed; /* 不设置的话页面滑动时，背景会不铺满*/
}
#skip {
  position: fixed;
  right: 20px;
  top: 20px;
  width: 100px;
  height: 35px;
  text-align: center;
  line-height: 35px;
  color: white;
  background-color: rgba(0, 0, 0, 0.4);
  border-radius: 10px;
}
</style>
